def plotspec(x, Ts):
fig = figure()
ax1 = fig.add_subplot(211)
ax1.plot(x)
q = fft.fft(x)
ax2 = fig.add_subplot(212)
ax2.plot(fft.fftfreq(len(x), Ts), abs(q))
Ts=1.0/100.0
time = 10.0
t = linspace(0, time, time/Ts)
h = exp(-t)
x=zeros(len(t))
x[int(1.0/Ts)] = 3.0
x[int(3.0/Ts)] = 2.0
y = convolve(h,x)
figure()
plot(x)
figure()
plot(h)
figure()
plot(y)
def plotconv(f,g):
Ts = 1.0/100.0
time = 10.0
t = linspace(0, time, time/Ts)
h = g(t)
x = f(t)
y = convolve(h,x)
figure()
plot(t, h)
figure()
plot(t, x)
figure()
plot(t, y[0:len(t)])
figure()
q = fft.fft(x)
plot(fft.fftfreq(len(x), Ts), abs(q))
figure()
q = fft.fft(y)
plot(fft.fftfreq(len(y), Ts), abs(q))
def noise(t):
return random.uniform(-1,1, len(t))
def exppulse(t):
return exp(-t)
plotconv(noise, exppulse)
plotconv(noise, sinc)